﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TestAngular.Migrations
{
    public partial class ProcurementsPurchaseRequisition : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BasicArchivesPurchaseRequisition",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    OrderTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SupplierId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    OperatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Mark = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    BussinessDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DocumentStatus = table.Column<int>(type: "int", nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesPurchaseRequisition", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesPurchaseRequisition_BasicArchivesOperator_OperatorId",
                        column: x => x.OperatorId,
                        principalTable: "BasicArchivesOperator",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesPurchaseRequisition_BasicArchivesPurchaseRequisitionType_OrderTypeId",
                        column: x => x.OrderTypeId,
                        principalTable: "BasicArchivesPurchaseRequisitionType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesPurchaseRequisition_BasicArchivesSupplier_SupplierId",
                        column: x => x.SupplierId,
                        principalTable: "BasicArchivesSupplier",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesPurchaseRequisitionLine",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ItemMasterId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ItemCode = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    ItemName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    ItemSpec = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Quantity = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    RemainingQuantity = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UnitPrice = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    DeliveryDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DocumentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    LineNo = table.Column<int>(type: "int", nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesPurchaseRequisitionLine", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesPurchaseRequisitionLine_BasicArchivesAuxiliaryUnit_UnitId",
                        column: x => x.UnitId,
                        principalTable: "BasicArchivesAuxiliaryUnit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesPurchaseRequisitionLine_BasicArchivesItemMaster_ItemMasterId",
                        column: x => x.ItemMasterId,
                        principalTable: "BasicArchivesItemMaster",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesPurchaseRequisitionLine_BasicArchivesPurchaseRequisition_DocumentId",
                        column: x => x.DocumentId,
                        principalTable: "BasicArchivesPurchaseRequisition",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesPurchaseRequisition_OperatorId",
                table: "BasicArchivesPurchaseRequisition",
                column: "OperatorId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesPurchaseRequisition_OrderTypeId",
                table: "BasicArchivesPurchaseRequisition",
                column: "OrderTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesPurchaseRequisition_SupplierId",
                table: "BasicArchivesPurchaseRequisition",
                column: "SupplierId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesPurchaseRequisitionLine_DocumentId",
                table: "BasicArchivesPurchaseRequisitionLine",
                column: "DocumentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesPurchaseRequisitionLine_ItemMasterId",
                table: "BasicArchivesPurchaseRequisitionLine",
                column: "ItemMasterId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesPurchaseRequisitionLine_UnitId",
                table: "BasicArchivesPurchaseRequisitionLine",
                column: "UnitId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BasicArchivesPurchaseRequisitionLine");

            migrationBuilder.DropTable(
                name: "BasicArchivesPurchaseRequisition");
        }
    }
}
